<?php session_start(); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<?php
if (isset($_SESSION['lang']))
    include_once "./language_files/submission2_" . $_SESSION['lang'] . ".php";
else
    include_once "./language_files/submission2_en.php";
if (!isset($_SESSION['member_id'])) {
    echo"<script type='text/javascript'>top.window.location='index.php';</script>";
    exit();
}

require_once "statics.php";
include "functions.php";
$conf_id = mysql_real_escape_string($_GET['conference_id']);
$confname = get_conference_name($conf_id);
echo"</br><span class=breadcrumbs><a href='subscriberConferencePage.php?conference_id={$conf_id}'>" . $confname . "</a>" . " > " . $lang['submit'] . "</span> </br></br>";

$bRet = bAuthorAll($_SESSION['member_id'], $conf_id);
if (is_string($bRet))
    echo $bRet;
else if (!$bRet) {
    echo"<script type='text/javascript'>top.window.location='index.php';</script>";
    exit();
}
?>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
        <meta http-equiv="X-UA-Compatible" content="IE=9" />
        <link href="style3.css" rel="stylesheet" type="text/css" />
        <title></title>
    </head>
    <body>
        <fieldset>
            <legend><?php echo $lang['submission_title']; ?></legend>
            <select id="category">
                <optgroup label="<?php echo $lang['submission_category']; ?>">
                    <?php
                    require_once "statics.php";
                    $submission_passed = false;
                    $rsCategories = rsSelect("category_id,submission_date", "conference_category", array("conference_id=", $conf_id, "AND", "submission_date>", "E__CURDATE()"));
                    if (is_string($rsCategories)) {
                        echo $rsCategories . "ERROR CODE: 0" . __LINE__;
                        exit();
                    }
                    if (mysql_num_rows($rsCategories) == 0) {
                        $submission_passed = true;
                    }
                    while ($row = mysql_fetch_assoc($rsCategories)) {
                        $sCategoryName = sCategoryName($row['category_id']);
                        echo "<option value='{$row['category_id']}' class='{$row['submission_date']}'>{$sCategoryName}</option>";
                    }
                    ?>
                </optgroup>
            </select><label id="submission_deadline" class="green"></label>
            <input type="hidden" id="passed" value="<?php if ($submission_passed) echo "true"; else echo "false"; ?>"/>
            <form action="submissionServer.php" id="file_upload" method="post" enctype="multipart/form-data">
                <input type="file" name="paper" id="paper" />
                <input type="hidden" name="type" id="type"/>
                <input type="hidden" name="conference_id" value="<?php echo formatText_safe($conf_id); ?>"/>
                <input type="submit" name="submit" id="submit" value="<?php echo $lang['submission_submit']; ?>"/>
            </form>
            <img id="loader" src="ajax-loader.gif" class="invisible"/><br/>
            <label id="success" class="green"><?php if (isset($_GET['success']) && isset($_GET['id'])) echo $lang['submission_success']. " ".
                    "<a href='co-authors.php?paper_id={$_GET['id']}&conference_id={$conf_id}'>Manage Co-authors now?</a>"; ?></label>
            <label id="failure" class="red"><?php if (isset($_GET['failure'])) echo $_GET['failure']; else if ($submission_passed == true) echo $lang['submission_passed']; ?></label>
        </fieldset>
        <?php include "jquery.php"; ?>
        <script type="text/javascript" src="functions.js"></script>
        <script type="text/javascript">
            //<![CDATA[
            $(document).ready(function()
            {
                check_top();
                deadline=$("#category option:selected").attr("class");
                if(deadline!=undefined)
                    $("#submission_deadline").html("Submission deadline: "+$("#category option:selected").attr("class"));
                $("#category").bind("change",function()
                {
                    if(deadline!=undefined)
                        $("#submission_deadline").html("Submission deadline: "+$("#category option:selected").attr("class"));
                });
                $("#file_upload").bind("submit",function(event)
                {
                    ext=$("#paper").val().split(".").pop().toLowerCase();
                    selected=$("#category option:selected").html();
                    $("#type").val($("#category").val());
                    if($("#passed").val()=="true" || selected==undefined)
                    {
                        event.preventDefault();
                        alert("Please choose a valid file within submission deadlines");
                        return false;
                    }
                    if(selected=="Short Paper" || selected=="Long Paper")
                    {
                        if(ext!=="pdf")
                        {
                            event.preventDefault();
                            alert("Please choose a valid PDF file within submission deadlines");
                            return false;
                        }
                        else
                            $("#loader").show();
                    }
                    else if(selected=="Poster")
                    {
                        if(ext!=="bmp")
                        {
                            event.preventDefault();
                            alert("Please choose a valid BMP file within submission deadlines");
                            return false;
                        }
                        else
                            $("#loader").show();
                    }
                    else if(selected=="Image")
                    {
                        if(ext!=="jpg" && ext!=="jpeg")
                        {
                            event.preventDefault();
                            alert("Please choose a valid JPG or JPEG file within sumbission deadlines");
                            return false;
                        }
                        else
                            $("#loader").show();
                    }
                    else if(selected=="Video")
                    {
                        if(ext!=="flv")
                        {
                            event.preventDefault();
                            alert("Please choose a valid FLV file within submission deadlines");
                            return false;
                        }
                        else
                            $("#loader").show();
                    }
                });
            });
            //]]>
        </script>
    </body>
</html>
